<?php

$roundId;
$holeNumber = 1;

$db = mysql_connect('localhost', 'kattilam_test', 'test') or die ('Unable to connect to DB!!');
mysql_select_db('kattilam_discgolfmobile', $db) or die (mysql_error($db));

$query1 = 'SELECT MAX(id) FROM round';
$result1 = mysql_query($query1, $db) or die (mysql_error($db));

while ($row = mysql_fetch_array($result1)) {
  extract($row);
  $roundId = $row[0];
  }

 error_log($_REQUEST['holeNumber'], 0);

$player1 = 'UPDATE result SET score_' . $_REQUEST['holeNumber'] . '="' . $_REQUEST['player1'] . '" WHERE player_name="'. $_REQUEST['player1Name'] . '" 
					 AND round_id='. $roundId . '';
mysql_query($player1, $db) or die (mysql_error($db));  

	if ($_REQUEST['player2Name'] != null) {
	$player2 = 'UPDATE result SET score_' . $_REQUEST['holeNumber'] . '="' . $_REQUEST['player2'] . '" WHERE player_name="'. $_REQUEST['player2Name'] . '" 
					 AND round_id='. $roundId . '';
	mysql_query($player2, $db) or die (mysql_error($db));  
	}

	if ($_REQUEST['player3Name'] != null) {
	$player3 = 'UPDATE result SET score_' . $_REQUEST['holeNumber'] . '="' . $_REQUEST['player3'] . '" WHERE player_name="'. $_REQUEST['player3Name'] . '" 
					 AND round_id='. $roundId . '';
	mysql_query($player3, $db) or die (mysql_error($db));  
	}

	if ($_REQUEST['player4Name'] != null) {
	$player4 = 'UPDATE result SET score_' . $_REQUEST['holeNumber'] . '="' . $_REQUEST['player4'] . '" WHERE player_name="'. $_REQUEST['player4Name'] . '" 
					 AND round_id='. $roundId . '';
	mysql_query($player4, $db) or die (mysql_error($db));  
	}
	
?>